<?


class Bills{
	function __construct(){
	}

	function get_balance($user_id = -1, $start_date = false, $end_date = false, $info){
		$start_date ? 0 : $start_date = date("Y-m-01");
		$end_date ? 0 : $end_date = date("Y-m-d 23:59");
		/*
		$sql = sprintf(sql::get_bills, $user_id, $start_date, $end_date);
		CCS::var_dump('get_bills', $sql, &$info);
		$result = mysql_query($sql);
		if ( $result ){
			$row = mysql_fetch_array($result);
			$info['bills_amount'] = &$row[0];
		}else{
			CCS::post_db_error(&$info);
			return 0;
		}
		*/
		$sql = sprintf(sql::get_fees_by_user_id, $user_id, $start_date);
		CCS::var_dump('get_fees_by_user_id', $sql, &$info);
		$result = mysql_query($sql);
		if ( $result ){
			$row = mysql_fetch_array($result);
			$info['fees_amount'] = &$row[0];
		}else{
			CCS::post_db_error(&$info);
			return 0;
		}

		$sql = sprintf(sql::get_pays, $user_id, $start_date, $end_date);
		CCS::var_dump('get_pays', $sql);
		$result = mysql_query($sql);
		if ( $result ){
			$pay_amount = 0;
			while ( $row = mysql_fetch_assoc($result)){
				$pay_amount += $row['amount'];
				$info['pays'][] = $row;
			}
			$info['pays_amount'] = &$pay_amount;
		}else{
			CCS::post_db_error(&$info);
			return 0;
		}
		$info['balance_month'] = date("Y-m");
		return 1;
	}

	function __destruct(){
	}
}

?>
